﻿@using BookShop.DTO
@using BookShop.Library.Common
@using BookShop.Library.Constant
@using PagedList
@using PagedList.Mvc
@model List<Publisher>
@{
    ViewBag.Title = "Quản lý Nhà xuất bản";
    var mod = Session[SessionKey.Moderator] != null ? (Moderator)Session[SessionKey.Moderator] : null;
}

<div class="portlet box blue">
    <div class="portlet-title">
        <div class="caption">
            <i class="fa fa-book"></i>@ViewBag.Title
        </div>
    </div>
    <div class="portlet-body form">
        <form class="form-horizontal" method="POST" action="@Url.Action("List")">
            <div class="form-body">
                <h3 class="form-section">Tìm kiếm</h3>
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">ID</label>
                            <div class="col-md-4">
                                <input type="text" class="form-control" value="@ViewBag.SearchId" name="publisherId" id="publisherId"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">Tên Thể loại</label>
                            <div class="col-md-8">
                                <input type="text" class="form-control" value="@ViewBag.SearchName" name="name" id="name"/>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">Trạng thái</label>
                            <div class="col-md-4">
                                <select class="form-control" name="status" id="status">
                                    <option value="">All</option>
                                    <option value="@PublisherStatus.Active">Active</option>
                                    <option value="@PublisherStatus.Inactive">Inactive</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-actions right">
                @if (CommonFunction.CheckModeratorRole(mod, ModeratorRole.PublisherWrite))
                {
                    <a target="_blank" href="@Url.Action("Add")" class="btn green" style="margin-right: 10px;"><i class="fa fa-plus"></i>Thêm mới</a>
                }
                <input type="submit" class="btn blue" value="Tìm kiếm" />
            </div>
        </form>
        <table class="table table-striped table-bordered table-hover dataTable" id="studyschedule_table">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Tên thể loại</th>
                    <th>Trạng thái</th>
                    <th>Thao tác</th>
                </tr>
            </thead>
            <tbody>
                @if (Model == null || Model.Count == 0)
                {
                    <tr>
                        <td colspan="4">No data to display</td>
                    </tr>
                }
                else
                {
                    foreach (var publisher in Model)
                    {
                    <tr>
                        <td>@publisher.Id</td>
                        <td>@publisher.Name</td>
                        <td>
                            @switch (publisher.Status)
                            {
                                case PublisherStatus.Active:
                                @("Active")
                                    break;
                                case PublisherStatus.Inactive:
                                @("Inactive")
                                    break;
                            }
                        </td>
                        <td>
                            <div class="btn-group">
                                <button type="button" class="btn blue dropdown-toggle" data-toggle="dropdown"><i class="fa fa-wrench"></i></button>
                                <ul class="dropdown-menu pull-right" role="menu">
                                    @if (CommonFunction.CheckModeratorRole(mod, ModeratorRole.PublisherWrite))
                                    {
                                        <li>
                                            <a target="_blank" href="@Url.Action("Edit", new { publisherId = publisher.Id })">Sửa</a>
                                        </li>
                                        <li>
                                            <a href="@Url.Action("Delete", new { publisherId = publisher.Id })" onclick="return confirm('Bạn có muốn xóa thể loại này?')">Xóa</a>
                                        </li>
                                    }
                                    <li>
                                        <a target="_blank" href="@Url.Action("Detail", new { publisherId = publisher.Id })">Chi tiết</a>
                                    </li>
                                </ul>
                            </div>
                        </td>
                    </tr>
                    }
                }
            </tbody>
        </table>
        <div class="records-count">@ViewBag.RecordsCount</div>
        @Html.PagedListPager((IPagedList)ViewBag.PageList, page => Url.Action("List",
       new
       {
           page,
           publisherId = ViewBag.SearchId,
           name = ViewBag.SearchName,
           status = ViewBag.SearchStatus,
       }), new PagedListRenderOptions
       {
           DisplayLinkToFirstPage = PagedListDisplayMode.Always,
           DisplayLinkToLastPage = PagedListDisplayMode.Always,
           DisplayLinkToPreviousPage = PagedListDisplayMode.IfNeeded,
           DisplayLinkToNextPage = PagedListDisplayMode.IfNeeded,
           DisplayLinkToIndividualPages = true,
           DisplayPageCountAndCurrentLocation = false,
           MaximumPageNumbersToDisplay = 5,
           DisplayEllipsesWhenNotShowingAllPageNumbers = true,
           EllipsesFormat = "&#8230;",
           LinkToFirstPageFormat = "««",
           LinkToPreviousPageFormat = "«",
           LinkToIndividualPageFormat = "{0}",
           LinkToNextPageFormat = "»",
           LinkToLastPageFormat = "»»",
           PageCountAndCurrentLocationFormat = "Page {0} of {1}.",
           ItemSliceAndTotalFormat = "Showing items {0} through {1} of {2}.",
           FunctionToDisplayEachPageNumber = null,
           ClassToApplyToFirstListItemInPager = null,
           ClassToApplyToLastListItemInPager = null,
           ContainerDivClasses = new[] { "pagination-container" },
           UlElementClasses = new[] { "pagination" },
           LiElementClasses = Enumerable.Empty<string>()
       })
    </div>
</div>

@section css
{
    <link type="text/css" rel="stylesheet" href="@Url.Content("~/Content/assets/global/plugins/bootstrap-toastr/toastr.min.css")"/>
}

@section javascript
{
    <script type="text/javascript" src="@Url.Content("~/Content/assets/global/plugins/bootstrap-toastr/toastr.min.js")"></script>
    @if (TempData[AlertMessage.TempDataKey] != null)
    {
        <script type="text/javascript">
            toastr['error']('@TempData[AlertMessage.TempDataKey].ToString()', 'Error');
            toastr.option = {
                "closeButton": true,
                "debug": false,
                "positionClass": "toast-top-right",
                "onclick": null,
                "showDuration": "1000",
                "hideDuration": "1000",
                "timeOut": "5000",
                "extendedTimeOut": "1000",
                "showEasing": "swing",
                "hideEasing": "linear",
                "showMethod": "fadeIn",
                "hideMethod": "fadeOut"
            }
        </script>
    }
    <script type="text/javascript">
        $(document).ready(function () {
            $('#status').val('@ViewBag.SearchStatus');
        });
    </script>
}